package com.example.b_308.medical;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.b_308.medical.controller.UserController;
import com.example.b_308.medical.model.Staff;
import com.example.b_308.medical.view.base.BaseActivity;
import com.example.b_308.medical.view.user.IUserView;

import org.w3c.dom.Text;

/**
 * Created by B-308 on 2017/11/22.
 */
public class Verification_codeActivity extends BaseActivity implements View.OnClickListener, IUserView {
    EditText et_phone;
    ImageView iv_return,iv_phone_delete;
    Button but_getCode;
    TextView tv_setting;
    UserController userController;
    int type;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verification_code);
        initView();
        initDate();
        initListener();
    }

    private void initListener() {
        iv_return.setOnClickListener(this);
        iv_phone_delete.setOnClickListener(this);
        but_getCode.setOnClickListener(this);
        et_phone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() == 0) {
                    iv_phone_delete.setVisibility(View.GONE);
                } else {
                    iv_phone_delete.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    private void initDate() {
        userController = new UserController(this);
        type=getIntent().getIntExtra("type",0);
    }


    private void initView() {
        iv_return= findView(R.id.iv_return);
        tv_setting= findView(R.id.tv_setting);
        tv_setting.setVisibility(View.GONE);
        et_phone = findView(R.id.et_phone);
        iv_phone_delete = findView(R.id.iv_phone_delete);
        but_getCode = findView(R.id.but_getCode);
        iv_phone_delete.setVisibility(View.GONE);
    }


    @Override
    public void loginSuccess(Staff staff) {

    }

    @Override
    public void registerSuccess() {

    }

    @Override
    public void getCodeSuccess() {
        tent2(RegisterActivity.class);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_return:
                tent2(LoginActivity.class);
                break;
            case R.id.iv_phone_delete:
                et_phone.setText("");
                break;
            case R.id.but_getCode:
                userController.getCode(et_phone.getText().toString(),type);
                break;
        }
    }
}
